package com.origin.learn.redisson;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.junit.Test;

import java.util.Map;

/**
 * @Description:
 * @Date: 2020/2/17
 * @Time: 12:11
 * @Created by:   dingtao
 * @Modified by:
 * @Modified at:
 */
public class TestSQL {
    
    @Test
    public void ttt2(){
        String result = "[{\"operation_time\":\"2020-02-11 08:12:21\",\"domain\":\"domain3\",\"raw_log\":\"2020-02-11 08:12:21 [login] ugi=testxinghuanes result=failed\",\"dst_port\":\"4444\",\"index_date\":\"20200217\",\"create_time\":\"1581992791519\",\"eqpt_device_type\":\"/Application/WEBServer\",\"dst_ip\":\"192.16.0.33\",\"username\":\"yidian\",\"action_result\":\"failed\",\"id\":\"727b3235-a2b5-44cd-a675-f495174ed39f\",\"db_name\":\"message\",\"status\":\"status1\",\"url\":\"url1\",\"operation_type\":\"login\",\"src_ip\":\"10.10.0.172\",\"risk_type\":\"multi_ip_login\",\"operation_target\":\"users\"},{\"operation_time\":\"2020-02-11 08:12:21\",\"domain\":\"domain4\",\"raw_log\":\"2020-02-11 08:12:21 [login] ugi=testxinghuanes result=failed\",\"dst_port\":\"2002\",\"index_date\":\"20200217\",\"create_time\":\"1581992677992\",\"eqpt_device_type\":\"/Application/WEBServer\",\"dst_ip\":\"172.16.0.12\",\"username\":\"u_zhujianwei\",\"action_result\":\"failed\",\"id\":\"2b62d683-b7e2-432e-995c-33798af1a8b4\",\"db_name\":\"users\",\"status\":\"status2\",\"url\":\"url3\",\"operation_type\":\"login\",\"src_ip\":\"10.10.0.172\",\"risk_type\":\"multi_ip_login\",\"operation_target\":\"users\"},{\"operation_time\":\"2020-02-11 08:12:21\",\"domain\":\"domain4\",\"raw_log\":\"2020-02-11 08:12:21 [login] ugi=testxinghuanes result=failed\",\"dst_port\":\"4444\",\"index_date\":\"20200217\",\"create_time\":\"1581992668719\",\"eqpt_device_type\":\"/Application/WEBServer\",\"dst_ip\":\"172.16.0.12\",\"username\":\"u_yx_monijigou\",\"action_result\":\"failed\",\"id\":\"d5bb4b88-60f0-43b0-bc6e-7b8500f3433b\",\"db_name\":\"message\",\"status\":\"status1\",\"url\":\"url1\",\"operation_type\":\"login\",\"src_ip\":\"10.10.0.172\",\"risk_type\":\"multi_ip_login\",\"operation_target\":\"click_infos\"},{\"operation_time\":\"2020-02-11 08:12:21\",\"domain\":\"domain4\",\"raw_log\":\"2020-02-11 08:12:21 [login] ugi=testxinghuanes result=failed\",\"dst_port\":\"4444\",\"index_date\":\"20200217\",\"create_time\":\"1581992604781\",\"eqpt_device_type\":\"/Application/WEBServer\",\"dst_ip\":\"172.16.0.12\",\"username\":\"u_yx_monijigou\",\"action_result\":\"failed\",\"id\":\"fcff3bbb-b6c5-474f-a95c-65d117846cb4\",\"db_name\":\"users\",\"status\":\"status3\",\"url\":\"url3\",\"operation_type\":\"login\",\"src_ip\":\"10.10.0.172\",\"risk_type\":\"account_abnormal\",\"operation_target\":\"message\"},{\"operation_time\":\"2020-02-11 08:12:21\",\"domain\":\"domain2\",\"raw_log\":\"2020-02-11 08:12:21 [login] ugi=testxinghuanes result=failed\",\"dst_port\":\"2002\",\"index_date\":\"20200217\",\"create_time\":\"1581992601829\",\"eqpt_device_type\":\"/Application/WEBServer\",\"dst_ip\":\"172.16.0.12\",\"username\":\"u_yx_monijigou\",\"action_result\":\"failed\",\"id\":\"5d6279a4-1462-4e1b-92d4-1e743e7e2f55\",\"db_name\":\"users\",\"status\":\"status4\",\"url\":\"url2\",\"operation_type\":\"login\",\"src_ip\":\"10.10.0.172\",\"risk_type\":\"try_to_thief_data\",\"operation_target\":\"message\"},{\"operation_time\":\"2020-02-11 08:12:21\",\"domain\":\"domain4\",\"raw_log\":\"2020-02-11 08:12:21 [login] ugi=testxinghuanes result=failed\",\"dst_port\":\"2002\",\"index_date\":\"20200217\",\"create_time\":\"1581992463035\",\"eqpt_device_type\":\"/Application/WEBServer\",\"dst_ip\":\"172.16.0.12\",\"username\":\"u_zhujianwei\",\"action_result\":\"failed\",\"id\":\"fb7b8f10-d6b5-44ae-b44b-6676a04b98c9\",\"db_name\":\"users\",\"status\":\"status3\",\"url\":\"url2\",\"operation_type\":\"login\",\"src_ip\":\"192.16.0.33\",\"risk_type\":\"multi_ip_login\",\"operation_target\":\"click_infos\"},{\"operation_time\":\"2020-02-11 08:12:21\",\"domain\":\"domain1\",\"raw_log\":\"2020-02-11 08:12:21 [login] ugi=testxinghuanes result=failed\",\"dst_port\":\"2002\",\"index_date\":\"20200217\",\"create_time\":\"1581992305777\",\"eqpt_device_type\":\"/Application/WEBServer\",\"dst_ip\":\"10.10.0.172\",\"username\":\"u_zhujianwei\",\"action_result\":\"failed\",\"id\":\"a2b3073f-b551-4ed6-8b4d-777bda3cdb94\",\"db_name\":\"users\",\"status\":\"status1\",\"url\":\"url4\",\"operation_type\":\"login\",\"src_ip\":\"172.16.0.12\",\"risk_type\":\"account_abnormal\",\"operation_target\":\"message\"},{\"operation_time\":\"2020-02-11 08:12:21\",\"domain\":\"domain4\",\"raw_log\":\"2020-02-11 08:12:21 [login] ugi=testxinghuanes result=failed\",\"dst_port\":\"2002\",\"index_date\":\"20200217\",\"create_time\":\"1581992268550\",\"eqpt_device_type\":\"/Application/WEBServer\",\"dst_ip\":\"192.16.0.33\",\"username\":\"u_zhujianwei\",\"action_result\":\"failed\",\"id\":\"b7fe8550-301f-4769-ac85-eb0bb6968d02\",\"db_name\":\"click_infos\",\"status\":\"status2\",\"url\":\"url1\",\"operation_type\":\"login\",\"src_ip\":\"172.16.0.12\",\"risk_type\":\"try_to_thief_data\",\"operation_target\":\"message\"},{\"operation_time\":\"2020-02-11 08:12:21\",\"domain\":\"domain2\",\"raw_log\":\"2020-02-11 08:12:21 [login] ugi=testxinghuanes result=failed\",\"dst_port\":\"4444\",\"index_date\":\"20200217\",\"create_time\":\"1581992239685\",\"eqpt_device_type\":\"/Application/WEBServer\",\"dst_ip\":\"10.10.0.172\",\"username\":\"u_zhujianwei\",\"action_result\":\"failed\",\"id\":\"248ad38b-94fe-4dc5-829c-f669b133bb72\",\"db_name\":\"click_infos\",\"status\":\"status4\",\"url\":\"url1\",\"operation_type\":\"login\",\"src_ip\":\"10.10.0.172\",\"risk_type\":\"account_abnormal\",\"operation_target\":\"users\"},{\"operation_time\":\"2020-02-11 08:12:21\",\"domain\":\"domain3\",\"raw_log\":\"2020-02-11 08:12:21 [login] ugi=testxinghuanes result=failed\",\"dst_port\":\"2002\",\"index_date\":\"20200217\",\"create_time\":\"1581992181327\",\"eqpt_device_type\":\"/Application/WEBServer\",\"dst_ip\":\"192.16.0.33\",\"username\":\"u_yx_monijigou\",\"action_result\":\"failed\",\"id\":\"2f010ab3-e1c2-451f-bd17-54d9c3ba702a\",\"db_name\":\"click_infos\",\"status\":\"status4\",\"url\":\"url1\",\"operation_type\":\"login\",\"src_ip\":\"174.16.0.88\",\"risk_type\":\"try_to_thief_data\",\"operation_target\":\"message\"}]";
        String need = "{\"eqpt_device_type\":[\"'/AppOperatingLog'\",\"'/Application'\",\"'/Application/APM'\",\"'/Application/DNSServer'\",\"'/Application/Database'\",\"'/Application/FTPServer'\",\"'/Application/MailServer'\",\"'/Application/WEBServer'\",\"'/AssessmentTool'\",\"'/BusinessApplication/BusinessRiskControlSystem'\",\"'/CellphoneSDK'\",\"'/DBAudit'\",\"'/DDOS'\",\"'/DLP'\",\"'/IDS/Honeypot'\",\"'/IDS/Host'\",\"'/IDS/Host/Antivirus'\",\"'/IDS/Host/FileIntegrity'\",\"'/IDS/Network'\",\"'/IDS/Network/WAF'\",\"'/IdentityManagement'\",\"'/IdentityManagement/LDAP'\",\"'/NetworkEquipment'\",\"'/NetworkEquipment/Firewall'\",\"'/NetworkEquipment/GSLB'\",\"'/NetworkEquipment/NPM'\",\"'/NetworkEquipment/NetFlow'\",\"'/NetworkEquipment/Router'\",\"'/NetworkEquipment/Switches'\",\"'/NetworkEquipment/loadblance'\",\"'/OperatingSystem'\",\"'/OperationGateway'\",\"'/Others'\",\"'/SecurityInformationManager'\",\"'/VPN'\",\"'/WebIntegrity'\"]}";

        JSONArray resultObj = JSON.parseArray(result);
        JSONObject needHighlightFields = JSON.parseObject(need);

        resultObj.forEach(map -> {
            Map<String, String> mm = (Map<String, String>)map;
            mm.keySet().forEach(key -> {
                if (needHighlightFields.containsKey(key)) {
                    String value = String.valueOf(mm.get(key));
                    String newValue = value;
                    JSONArray jsonArray = (JSONArray)needHighlightFields.get(key);
                    for (Object object : jsonArray) {
                        String srcQueryValue = String.valueOf(object);
                        if (newValue.contains(srcQueryValue)) {
                            newValue = newValue.replaceAll(srcQueryValue, "<idss-span style='" + "DADASG" + "'>" + srcQueryValue + "</idss-span>");
                        }
                    }
                    ((Map<String, String>) map).put(key, newValue);
                }
            });
        });

    }

    @Test
    public void ttt(){
        String value = "/Application/WEBServer";
        String query = "**Application**";
        String newValue = value;
        newValue = newValue.replaceAll(query, "<idss-span style='color'>"+query+"</idss-span>");
        System.out.println(newValue);
    }

    @Test
    public void test(){
//        String x = \"eqpt_device_type='/AppOperatingLog'\";
//        Map<String, String> result = TranswarpSqlUtil.RegexHelper.testRegex(x, \"highlight\");
//
//        int s=1;
    }
}
